#   Copyright (c)  2021 FromVB2Python
#   FromVB2Python is licensed under Mulan PSL v2.
#   You can use this software according to the terms and conditions of the Mulan PSL v2. 
#   You may obtain a copy of Mulan PSL v2 at:
#            http://license.coscl.org.cn/MulanPSL2 
#   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
#   See the Mulan PSL v2 for more details.  
# 001-学考-温度转换-201510-14学考选考 
import tkinter as tk
def convert():
    '''根据整数1与整数2生成温度转换对照表'''
    a = int(txt1.get())  # 获取第1个数
    b = int(txt2.get())  # 获取第2个数
    if a > b:
        a, b = b, a
    listbox1.delete(1, tk.END)
    for i in range(a, b+1):
        f = i * 9 / 5 + 32  # 摄氏温度转化为华氏温度
        # 列表框输出
        listbox1.insert(tk.END, '    {:<5}             {:<5}'.format(i, f))


# 建立窗口
win = tk.Tk()
win.title('温度转换')
win.resizable(0, 0)
# 建立组件
lb1 = tk.Label(win, text = '输入第1个整数')
lb2 = tk.Label(win, text = '输入第2个整数')
txt1 = tk.Entry(win)
txt1.insert(0, '15')
txt2 = tk.Entry(win)
txt2.insert(0, '10')
listbox1 = tk.Listbox(win)
listbox1.insert(0,'  摄氏温度    华氏温度')
cmd = tk.Button(win, text = 'Command1', command = convert)
# 组件布局
lb1.grid(row=0, column=0)
lb2.grid(row=1, column=0)
txt1.grid(row=0, column=1)
txt2.grid(row=1, column=1)
cmd.grid(row=2,column=1)
listbox1.grid(row=0,column=2,rowspan=3)
# 接收窗口事件
win.mainloop()